home *** CD-ROM | disk | FTP | other *** search
/ Aminet 22 / Aminet 22 (1997)(GTI - Schatztruhe)[!][Dec 1997].iso / Aminet / dev / src / ConfigFileSrc.lha / ConfigFileSrc12 / Library / Utils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-02  |  3.0 KB  |  156 lines

  1. /*
  2. **        $PROJECT: ConfigFile.library
  3. **        $FILE: Utils.c
  4. **        $DESCRIPTION: Misc functions.
  5. **
  6. **        (C) Copyright 1996-1997 Marcel Karas
  7. **             All Rights Reserved.
  8. */
  9.  
  10. #include "LibBase.h"
  11. #include "Funcs/GlobalVars.h"
  12. #include "Utils.h"
  13.  
  14. IMPORT struct ExecBase        *SysBase;
  15. IMPORT struct DosLibrary    *DOSBase;
  16.  
  17. /**************************************************************************/
  18.  
  19.     /* GetFileSize():
  20.      *
  21.      *    return the length of the file.
  22.      */
  23.  
  24. LONG GetFileSize ( BPTR FH )
  25. {
  26.     struct FileInfoBlock FIB;
  27.  
  28.     ExamineFH (FH, &FIB);
  29.  
  30.     return(FIB.fib_Size);
  31. }
  32.  
  33. /**************************************************************************/
  34.  
  35.     /* NewStr():
  36.      *
  37.      *    allocate a new string.
  38.      */
  39.  
  40. STRPTR NewStr ( APTR MemPool, UBYTE Length )
  41. {
  42.     UBYTE *Ret;
  43.  
  44.     if ( Ret = (UBYTE *) MyAllocPooled (MemPool,
  45.                     ( Length + (sizeof(UBYTE) * 2) ) ) )
  46.     {
  47.         *Ret = Length;
  48.         return ((STRPTR) ( Ret + 1 ));
  49.     }
  50.  
  51.     return (FALSE);
  52. }
  53.  
  54.     /* DelStr():
  55.      *
  56.      *    dispose the string.
  57.      */
  58.  
  59. VOID DelStr ( APTR MemPool, STRPTR String )
  60. {
  61.     String--;
  62.     MyFreePooled (MemPool, String, (*String + (sizeof(UBYTE) * 2)));
  63. }
  64.  
  65. STRPTR DupStr ( APTR MemPool, STRPTR String )
  66. {
  67.     STRPTR    Str;
  68.  
  69.     Str = NewStr (MemPool, StrLen (String));
  70.     StrCpy (Str, String);
  71.  
  72.     return (Str);
  73. }
  74.  
  75. /*
  76. STRPTR DupStrF ( STRPTR String )
  77. {
  78.     STRPTR    Str;
  79.  
  80.     Str = NewStr (*( String - 1 ));
  81.     StrCpy (Str, String);
  82.  
  83.     return (Str);
  84. }
  85. */
  86. /**************************************************************************/
  87.  
  88. /* Debug Functions */
  89.  
  90. #define DEBUGFILE    "RAM:CFDebugFile"
  91.  
  92. #if (CF_FUNC_DEBUG || CF_STEP_DEBUG || CF_MEMA_DEBUG)
  93.  
  94. SaveDS VOID bug ( STRPTR Fmt , ... )
  95. {
  96.     BPTR    FH = Open (DEBUGFILE, MODE_READWRITE);
  97.     Seek (FH, 0, OFFSET_END);
  98.     VFPrintf (FH, Fmt, (ULONG *)&Fmt+1);
  99.     Close (FH);
  100. }
  101.  
  102. #endif
  103.  
  104. /**************************************************************************/
  105.  
  106. #ifdef CF_MEMA_DEBUG
  107.  
  108. #undef MyAllocPooled
  109. #undef MyCreatePool
  110. #undef MyDeletePool
  111. #undef MyFreePooled
  112.  
  113. #ifndef POOLS_V39
  114.  
  115. #define MyAllocPooled(a,b)        AsmAllocPooled (a, b, SysBase)
  116. #define MyCreatePool(a,b,c)    AsmCreatePool (a, b, c, SysBase)
  117. #define MyDeletePool(a)            AsmDeletePool (a, SysBase)
  118. #define MyFreePooled(a,b,c)    AsmFreePooled (a, b, c, SysBase)
  119.  
  120. #else
  121.  
  122. #define MyAllocPooled(a,b)        AllocPooled (a, b)
  123. #define MyCreatePool(a,b,c)    CreatePool (a, b, c)
  124. #define MyDeletePool(a)            DeletePool (a)
  125. #define MyFreePooled(a,b,c)    FreePooled (a, b, c)
  126.  
  127. #endif
  128.  
  129. APTR DEBAllocPooled ( APTR MemPool , ULONG Size )
  130. {
  131.     APTR    NewMem = MyAllocPooled(MemPool,Size);
  132.     bug("   $%08lx = AllocPooled($%08lx,%ld)\n", NewMem, MemPool, Size);
  133.     return (NewMem);
  134. }
  135.  
  136. APTR DEBCreatePool ( ULONG MemAttrs , ULONG PuddleSize , ULONG ThreshSize )
  137. {
  138.     APTR    NewPool = MyCreatePool(MemAttrs, PuddleSize, ThreshSize);
  139.     bug("   $%08lx = CreatePool($%lx,%ld,%ld)\n", NewPool, MemAttrs, PuddleSize, ThreshSize);
  140.     return (NewPool);
  141. }
  142.  
  143. VOID DEBDeletePool ( APTR MemPool )
  144. {
  145.     bug("   DeletePool($%08lx)\n", MemPool);
  146.     MyDeletePool(MemPool);
  147. }
  148.  
  149. VOID DEBFreePooled ( APTR MemPool , APTR Mem , ULONG Size )
  150. {
  151.     bug("   FreePooled($%08lx,$%08lx,%ld)\n", MemPool, Mem, Size);
  152.     MyFreePooled(MemPool, Mem, Size);
  153. }
  154.  
  155. #endif
  156.